package cn.jly.flink.repartition;

import cn.jly.flink.utils.FlinkUtils;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @PackageName cn.jly.flink.repartition
 * @ClassName CustomPartitionDemo
 * @Description 自定义分区器
 * @Author 姬岚洋
 * @Date 2021/1/27 下午 7:02
 */
public class CustomPartitionDemo {
    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment env = FlinkUtils.getStreamExecutionEnv();

        final DataStreamSource<String> dataStreamSource = env.readTextFile("d:/SensorReading.txt");
        dataStreamSource.print("input");

        // 1. shuffle重分区
        dataStreamSource.shuffle()
                .print("shuffle");

        // 2. keyBy也可以重分区

        // 3. global将所有的数据汇总到下游同一个分区中

        FlinkUtils.executeStream(env, "CustomPartitionDemo");
    }
}
